package at.btd.bsk.gps;

import at.btd.bsk.MainActivity;
import at.btd.bsk.entities.Trip;
import at.btd.bsk.entities.Waypoint;
import at.btd.bsk.observer.Observer;

import com.google.android.maps.MapView;

public class GPSListener implements Observer<Waypoint> {
    private MainActivity activity = null;
	private Trip trip = null;
	private MapView mapView = null;

	public GPSListener(Trip run, MapView mapView, MainActivity activity) {
		this.trip = run;
		this.mapView = mapView;
		this.activity = activity;
	}

	@Override
	public void notify(Waypoint p) {
		// run set, add new waypoint
		if (this.trip != null) {
			this.trip.addWaypoint(p);
		}

		// map set, center new waypoint and redraw map to show new line
		if (this.mapView != null) {
			this.mapView.getController().animateTo(p.getGeoPoint());
			this.mapView.postInvalidate();
		}
		
		if (this.activity != null) {
		    this.activity.postNotificationToArduino(p);
		}
	}

  
    public boolean isWaitObserver() {
        // TODO Auto-generated method stub
        return false;
    }

}
